#ifndef DATABASECLASS_H
#define DATABASECLASS_H
#include <QString>
#include <stdio.h>
#include <stdlib.h>
#include <QDebug>
#include <QTimer>
#include <QtSql>
#include <QString>

#define CREATE_INFO_VOICE "CREATE TABLE [guard_dict_voice] ([id] INTEGER PRIMARY KEY AUTOINCREMENT, [code] INTEGER(10), [voice] VARCHAR(30), [download_flag] VARCHAR(10), [created_at] TIMESTAMP DEFAULT (datetime('now','localtime')))"
#define CREATE_INFO_RECORD " CREATE TABLE [voice_record] ([id] INTEGER PRIMARY KEY AUTOINCREMENT, [code] INTEGER(10) CONSTRAINT [CodeID] REFERENCES [guard_dict_voice]([code]), [dev_sn] VARCHAR(30), [download_flag] VARCHAR(10), [created_at] TIMESTAMP DEFAULT (datetime('now','localtime')))"
typedef struct{
    QString id;
    QString uid;
    QString sn;
    QString box;
}boxIdInfo;

typedef struct{
    QString id;
    QString code;
    QString open_flag;
    QString voice;
}voiceInfo;
typedef struct
{
  //  QString clent_id;
  //  QString client_ip;
    int tcp_id;
    QString tcp_ip;
    int tcp_port;
}tcpInfo;

typedef struct{
    QString ic_sn;
    QString end_ate;
    QString house;
    QString id;
    QString voice_id;
    QString down_flag;
}conInfo;

typedef struct{
    QString community_id;
    QString root_id;
}houseInfo;

class databaseClass
{
public:
    databaseClass();
    QSqlDatabase mySql_db;
    QSqlDatabase sqlite_db;
public slots:
    bool  controller_sn_infor(QString dev_no);
    bool mj_controller_sn_infor(QString dev_no,houseInfo *info);
    bool  box_id_infor(QString controller_sn,QString card_sn,boxIdInfo *boxInfo);
    QString  box_no_infor(int flag,QString id,QString uid);
    bool  box_sn_infor(int flag,QString controller_sn,boxIdInfo *boxInfo);
    bool writeOpenLog(QString card_sn,QString cabinet_id,QString box_no,QString uid);
    bool writeGpsLog(QString vehicle_sn,QString temprature,QString lng_gps,QString lat_gps);
    QString vehicle_infor(QString id);
    bool privilege_infor(QString dev_id,QString ic_code);
    bool download_card(QString dev_no);
    bool consumer_info(QString Dev_no,conInfo *consumerInfo);
    bool consumer_change(QString flag,QString Dev_sn,QString card_sn);
    bool house_change(QString flag,QString dev_sn,QString house_id);
    bool voice_change(QSqlDatabase *db,QString flag,QString dev_sn,QString id);

    bool box_no_change(int flag,QString controller_sn,QString card_sn);
    bool record_in_out(QString pass_no,QString controller_sn,QString ic_sn,QString passtime);
    bool cfg_controller_update_heart(QString Dev_sn);
    bool info_cabinet_update_heart(QString Dev_sn);
    //2017-10-23 14:56 ??
    QString info_cabinet_select_id(QString controller_sn);
    bool info_consumer_update_downFlag(int flag,QString cabinet_id);
    bool info_consumer_check_downFlag(int flag,QString controller_sn);
    bool info_consumer_select_downFlag(QString cabinet);

    void mj_Consumer_Change(QString flag,QString dev_no);
    void mj_houseId_Change(QString flag,QString house_id);
    bool info_voice_downFlag(QSqlDatabase *db,QString flag,QString dev_sn,QString code);
    bool voice_infor(QSqlDatabase *db,QString dev_no,voiceInfo *info);
    void databaseinit(QString dbname);

    void voiceInfo_down(QSqlDatabase *Msql_db,QSqlDatabase *Lsql_db);
    void voiceDownFlag_change(QSqlDatabase *Msql_db,QString flag,QString code);
    void voiceInfo_Find(QSqlDatabase *Lsql_db,QString dev_no);
};

#endif // DATABASECLASS_H
